import java.util.PriorityQueue;

public class KthLargest {
    //数据流第k大元素
    PriorityQueue<Integer> queue;
    private int k;
    private int[] nums;
    public KthLargest(int k, int[] nums) {
        this.k = k;
        this.nums = nums;
        queue = new PriorityQueue<Integer>();
        for(int i : nums) {
            add(i);
        }
    }

    public int add(int val) {
        queue.offer(val);
        if(queue.size() > k) {
            queue.poll();
        }
        return queue.peek();
    }
}
